# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-ctypes
pkgver=0.20.1
pkgrel=2
pkgdesc="Combinators for binding to C libraries without writing any C"
url="https://github.com/ocamllabs/ocaml-ctypes"
arch="all !riscv64 !loongarch64" # ocaml
license="MIT"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="
	libffi-dev
	ocaml
	ocaml-bigarray-compat-dev
	ocaml-compiler-libs
	ocaml-findlib-dev
	ocaml-integers-dev
	ocaml-stdlib-shims
	"
options="!check"  # requires lwt and ounit
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/ocamllabs/ocaml-ctypes/archive/$pkgver.tar.gz"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	export OCAMLFIND_LDCONF=ignore
	make
}

package() {
	export OCAMLFIND_DESTDIR="$pkgdir"/usr/lib/ocaml
	mkdir -vp "$OCAMLFIND_DESTDIR/stublibs"
	make install
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
f95e65ce5003a07634afcbee431cb23c54c8335f926074615fc8d76ab777b9d2fce8f75bb25bbb6ed9550a7d6237fb377aa9ad65a426d2d7e387f86c1158fe4a  ocaml-ctypes-0.20.1.tar.gz
"
